<?php

class AdminController extends BaseController {
    
    public $moderPartner = false;
    public $moderUser = false;
    public $moderNews = false;
    public $moderBlog = false;
    
    public function filters() {
        return array(
            'accessControl -login',
        );
    }
    
    public function accessRules() {
        $controllerId = $this->getId();
        if (!$controllerId) {
            return array();
        }
        $acl = Yii::app()->params['adminAcl'];
        if (!$acl) {
            return array();
        }
        if (isset($acl[$controllerId])) {            
            return $acl[$controllerId];
        }
        return array();
    }
    
    protected function beforeAction($action) {
        $action = Yii::app()->controller->action->id;
        if($action != 'login' && !Yii::app()->user->checkAccess('admin')) {
            if(Yii::app()->user->checkAccess('redactor') && $action != 'redactor' && $action != 'review' && $action != 'index') throw new CHttpException(403);
            else return true;
            $user = Yii::app()->user->getAllUserInfo();
            if($user['moderBlog']) $this->moderBlog = true;
            if($user['moderNews']) $this->moderNews = true;
            if($user['moderUser']) $this->moderUser = true;
            if($user['moderPartner']) $this->moderPartner = true;
            if($action == 'partnercat' && $action == 'partner' && !$this->moderPartner) throw new CHttpException(403);
            if($action == 'news' && !$this->moderNews) throw new CHttpException(403);
            if($action == 'banuser' && !$this->moderUser) throw new CHttpException(403);
            if(($action == 'blogcat' || $action == 'blogart') && !$this->moderBlog) throw new CHttpException(403);
            if($action!='blogcat' && $action!='blogart' && $action!='banuser' && $action!='news' && $action!='partnercat' && $action!='partner' && $action!='index') throw new CHttpException(403);
            if(!Yii::app()->user->checkAccess('redactor') && !$this->moderBlog && !$this->moderNews && !$this->moderUser && !$this->moderPartner) throw new CHttpException(403);
        }
        if(Yii::app()->user->checkAccess('admin')) $this->moderBlog = $this->moderNews = $this->moderUser = $this->moderPartner = true;
        return true;
    }
}